package com.xgc.book.bookserver.controller.api;

import com.xgc.book.bookserver.bean.NoticeBean;
import com.xgc.book.bookserver.service.AdService;
import com.xgc.book.bookserver.service.CodeService;
import com.xgc.book.bookserver.service.NoticeService;
import com.xgc.book.bookserver.service.VipService;
import com.xgc.book.bookserver.util.ResultJson;
import com.xgc.book.bookserver.util.form.LoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @ClassNameApiIndexController
 * @Author:王润之
 * @Description
 * @DateTime2023/11/27 13:42
 **/
@RestController
@RequestMapping(value = {"/api/v1", "/wx/v1"})
public class ApiIndexController {
    @Autowired
    private AdService adService;

    @Autowired
    private CodeService codeService;

    @Autowired
    private VipService vipService;

    @Autowired
    private NoticeService noticeService;

    @GetMapping("/banner/list")
    public ResultJson getAdList() {
        return adService.getAdList();
    }

    @GetMapping("/send/msm")
    public ResultJson sendMsm(String uuid, String code, String phone) {
        if (!codeService.checkKaptcha(uuid, code)) {
            return ResultJson.error("图片验证码错误！");
        }
        return codeService.sendMsm(phone);
    }

    @PostMapping("/phone/login")
    public ResultJson pcLogin(@RequestBody LoginForm loginForm) {
        loginForm.setType(1);
        return vipService.login(loginForm);
    }

    @GetMapping("/wx/login")
    public ResultJson wxLogin(String jsCode) {
        return vipService.wxLogin(jsCode);
    }

    @GetMapping("/notice/page")
    public ResultJson noticePage(int page, int limit) {
        NoticeBean noticeBean = new NoticeBean();
        noticeBean.setExpires(new Date());
        return noticeService.getPage(page, limit, noticeBean);
    }
}
